﻿Public Class MusteriGecisContractCreate
    Inherits System.Web.UI.Page
    Dim smc_id As String
    Dim sm_id As String
    Dim hlcode As String
    Dim dn_id As String
    Dim dn_num As String
    Dim dn_type As String
    Dim dirnum_npcode As String
    Dim i As Integer
    Dim pin_customer_id As Integer


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ErrorMessage.Text = ""
        Try
            If Session("user") = "" Or Session("user") Is Nothing Then
                Session("message") = "!!Session Timeout!!,Tekrar Giriş Yapmalısınız"
                Response.Clear()
                Response.Status = "302 Object Moved"
                Response.RedirectLocation = "CX_Exception.aspx"
                Response.End()
            End If
            If Convert.ToInt32(Session("secim")) = 1 Then
                'dt2 = ccapps.persistent.YenidenAktivasyon.SMECustCodeSearch(custcode) 
                Label5.Text = " İşlem Tipi :Yeniden Aktivasyon "
            ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                'dt2 = ccapps.persistent.Gpo2Gpo.SMECustCodeSearch(custcode)
                Label5.Text = "İşlem Tipi  :Gpo2Gpo "
            ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                'dt2 = ccapps.persistent.GPO2Avea.SMECustCodeSearch(custcode)
                Label5.Text = " İşlem Tipi : Gpo2Avea "
            ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                'dt2 = ccapps.persistent.Avea2GPO.SMECustCodeSearch(custcode)
                Label5.Text = " İşlem Tipi : Avea2Gpo "

            ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                'dt2 = ccapps.persistent.Avea2GPO.SMECustCodeSearch(custcode)
                Label5.Text = " İşlem Tipi : Devirişlem "
            End If

            chck_INTERNATIONAL_CALL.Enabled = False
            chck_INTERNATIONAL_ROAMING.Enabled = False
            'chck_INTERNATIONAL_CALL.Checked = False
            'chck_INTERNATIONAL_ROAMING.Checked = False

            Label2.Text = Session("cust_type")

            If (Label2.Text = "bireysel") Then  ' burada eger müşteri bireysel olarak işlem yapıyorsa tarife secili gelip tarife kısmı hidden olur.
                Label2.Text = Session("tarife")
                Dim rpcode_from_bireysel As Integer = Convert.ToInt32(Label2.Text)
                RPServiceStatusBireysel(rpcode_from_bireysel)
                hid.Visible = False

            End If


            If (Session("durum") = "MevcutSME") Then    ' müşteri Mevcut Tabledan gelirse
                Label1.Text = Session("customer_id")
                Dim rpcode_from_mevcut As Integer = Convert.ToInt32(Label1.Text) 'Buralar diğer sayfalarada eklenecek
                RPServiceStatus(rpcode_from_mevcut) '25.02.2013

            Else
                Label1.Text = Session("customer_id")   'müşteri bireyselden gelirse
            End If

            pin_customer_id = Convert.ToInt32(Label1.Text)

            If Not IsPostBack Then
                Dim dtmusteribilgileri As DataTable = New DataTable() '= GetCustomerCode(Convert.ToInt32(Label1.Text))
                Dim dtmusteribilgileri2 As DataTable = New DataTable()  '= GetCustomerInfo(Convert.ToInt32(Label1.Text))

                If Convert.ToInt32(Session("secim")) = 1 Then
                    dtmusteribilgileri = ccapps.persistent.YenidenAktivasyon.GetCustomerCode(Convert.ToInt32(Label1.Text))
                    dtmusteribilgileri2 = ccapps.persistent.YenidenAktivasyon.GetCustomerInfo(Convert.ToInt32(Label1.Text))

                ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                    dtmusteribilgileri = ccapps.persistent.Gpo2Gpo.GetCustomerCode(Convert.ToInt32(Label1.Text))
                    dtmusteribilgileri2 = ccapps.persistent.Gpo2Gpo.GetCustomerInfo(Convert.ToInt32(Label1.Text))

                ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                    dtmusteribilgileri = ccapps.persistent.GPO2Avea.GetCustomerCode(Convert.ToInt32(Label1.Text))
                    dtmusteribilgileri2 = ccapps.persistent.GPO2Avea.GetCustomerInfo(Convert.ToInt32(Label1.Text))

                ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                    dtmusteribilgileri = ccapps.persistent.Avea2GPO.GetCustomerCode(Convert.ToInt32(Label1.Text))
                    dtmusteribilgileri2 = ccapps.persistent.Avea2GPO.GetCustomerInfo(Convert.ToInt32(Label1.Text))
                ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                    dtmusteribilgileri = ccapps.persistent.CustomerCreate.GetCustomerCode(Convert.ToInt32(Label1.Text))
                    dtmusteribilgileri2 = ccapps.persistent.CustomerCreate.GetCustomerInfo(Convert.ToInt32(Label1.Text))

                End If

                musteribilgileri.InnerHtml = "<span style='FONT-SIZE: 12px'>MÜŞTERİ BİLGİLERİ: <BR/></span>"
                musteribilgileri.InnerHtml += "<span style='FONT-SIZE: 12px'>CustCode: " + dtmusteribilgileri.Rows(0)("custcode").ToString() + "</span>" + "<div style='FONT-SIZE:12px;'>CustFirstName-CustLastName:  "
                musteribilgileri.InnerHtml += dtmusteribilgileri2.Rows(0)("ccfname").ToString() + " - " + dtmusteribilgileri2.Rows(0)("cclname").ToString() + "</div>"
            End If

        Catch ex As Exception
            ErrorMessage.Text = ex.ToString()
        End Try
      

    End Sub


    Private Sub AktivasyonReason()

        DDL_RS_CODE.Items.Clear()
        Dim dt2 As DataTable = New DataTable() ' = aktivasyonType()

        If Convert.ToInt32(Session("secim")) = 1 Then
            dt2 = ccapps.persistent.YenidenAktivasyon.aktivasyonType()
        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
            dt2 = ccapps.persistent.Gpo2Gpo.aktivasyonType()
        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
            dt2 = ccapps.persistent.GPO2Avea.aktivasyonType()
        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
            dt2 = ccapps.persistent.Avea2GPO.aktivasyonType()
        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
            dt2 = ccapps.persistent.CustomerCreate.aktivasyonType()
        End If

        If dt2.Rows.Count > 0 Then
            For Each dr2 As DataRow In dt2.Rows
                DDL_RS_CODE.Items.Add(New ListItem(dr2("rs_desc").ToString(), dr2("RS_ID").ToString())) 'rs_desc ve rscode Databasedeki sql variablelarının isimleri' 
            Next
        End If
    End Sub
    Private Sub DealerSecim()

        Dim smid As Integer

        If (TB_SM_SERIALNUM.Text <> "") Then
            'Dim dt2 As DataTable = GetMsisdn(TB_SM_SERIALNUM.Text.Trim())

            Dim dt2 As DataTable = New DataTable() ' = aktivasyonType()

            If Convert.ToInt32(Session("secim")) = 1 Then
                dt2 = ccapps.persistent.YenidenAktivasyon.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
            ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                dt2 = ccapps.persistent.Gpo2Gpo.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
            ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                dt2 = ccapps.persistent.GPO2Avea.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
            ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                dt2 = ccapps.persistent.Avea2GPO.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
            ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                dt2 = ccapps.persistent.CustomerCreate.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
            End If

            If dt2.Rows.Count > 0 Then
                For Each dr3 As DataRow In dt2.Rows
                    smid = Convert.ToInt32(dr3("SM_ID").ToString())
                Next
            End If
        End If
        ' Dim dt3 As DataTable = DealerInfo(smid)

        Dim dt3 As DataTable = New DataTable() ' = aktivasyonType()

        If Convert.ToInt32(Session("secim")) = 1 Then
            dt3 = ccapps.persistent.YenidenAktivasyon.DealerInfo(smid)
        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
            dt3 = ccapps.persistent.Gpo2Gpo.DealerInfo(smid)
        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
            dt3 = ccapps.persistent.GPO2Avea.DealerInfo(smid)
        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
            dt3 = ccapps.persistent.Avea2GPO.DealerInfo(smid)
        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
            dt3 = ccapps.persistent.CustomerCreate.DealerInfo(smid)
        End If


        If dt3.Rows.Count > 0 Then
            For Each dr3 As DataRow In dt3.Rows
                ' Label8.Text = dr3("ccfname").ToString() & "  " & dr3("cclname").ToString() & "  " & dr3("CCCITY").ToString()
            Next
        End If
    End Sub

    Private Sub TarifeSecim()

        DDL_RPCODE.Items.Clear()
        'Dim dt3 As DataTable = GetTariffContract(pin_customer_id)

        Dim dt3 As DataTable = New DataTable() ' = aktivasyonType()

        If Convert.ToInt32(Session("secim")) = 1 Then
            dt3 = ccapps.persistent.YenidenAktivasyon.GetTariffContract(pin_customer_id)
        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
            dt3 = ccapps.persistent.Gpo2Gpo.GetTariffContract(pin_customer_id)
        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
            dt3 = ccapps.persistent.GPO2Avea.GetTariffContract(pin_customer_id)
        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
            dt3 = ccapps.persistent.Avea2GPO.GetTariffContract(pin_customer_id)
        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
            dt3 = ccapps.persistent.CustomerCreate.GetTariffContract(pin_customer_id)
        End If

        If dt3.Rows.Count > 0 Then
            For Each dr3 As DataRow In dt3.Rows
                DDL_RPCODE.Items.Add(New ListItem(dr3("des").ToString(), dr3("tmcode").ToString()))

            Next
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        i = 1
        lblSMHata.Text = ""
        TB_MSISDN.Text = ""
        TB_NewDealer.Text = ""
        If (chckPrelinked.Checked = True) Then


            If (TB_SM_SERIALNUM.Text <> "") Then
                'Dim dt3 As DataTable = GetMsisdn(TB_SM_SERIALNUM.Text)

                Dim dt3 As DataTable = New DataTable() ' = aktivasyonType()

                If Convert.ToInt32(Session("secim")) = 1 Then
                    dt3 = ccapps.persistent.YenidenAktivasyon.GetMsisdn(TB_SM_SERIALNUM.Text)
                ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                    dt3 = ccapps.persistent.Gpo2Gpo.GetMsisdn(TB_SM_SERIALNUM.Text)
                ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                    dt3 = ccapps.persistent.GPO2Avea.GetMsisdn(TB_SM_SERIALNUM.Text)
                ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                    dt3 = ccapps.persistent.Avea2GPO.GetMsisdn(TB_SM_SERIALNUM.Text)
                ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                    dt3 = ccapps.persistent.CustomerCreate.GetMsisdn(TB_SM_SERIALNUM.Text)
                End If

                If dt3.Rows.Count = 0 Then
                    lblSMHata.Text = "Girmiş olduğunuz ICC-ID deactive durumdadır. Lütfen farklı bir ICC-ID deneyiniz"

                ElseIf dt3.Rows.Count > 0 Then
                    For Each dr3 As DataRow In dt3.Rows



                        If dr3("sm_status").ToString() = "d" Then
                            lblSMHata.Text = "Girmiş olduğunuz ICC-ID deactive durumdadır. Lütfen farklı bir ICC-ID deneyiniz"
                        End If

                        If dr3("sm_status").ToString() = "a" Then
                            lblSMHata.Text = "Girmiş olduğunuz ICC-ID zaten kullanılmaktadır. Lütfen farklı bir ICC-ID deneyiniz"

                        End If

                        If dr3("sm_status").ToString() = "p" Then
                            lblSMHata.Text = "Girmiş olduğunuz ICC-ID ye ait bir telefon numarası yoktur. Lütfen farklı bir ICC-ID deneyiniz"

                        End If

                        If dr3("sm_status").ToString() = "r" Then
                            TB_MSISDN.Text = dr3("dn_num").ToString().Substring(2, 10)
                            smc_id = dr3("SMC_ID").ToString() '/*smc_id*/
                            sm_id = dr3("SM_ID").ToString()
                            hlcode = dr3("hlcode").ToString()
                            dn_id = dr3("DN_ID").ToString()   '/*dn_id*/
                            dn_num = dr3("dn_num").ToString() '/*dirnum*/
                            dn_type = dr3("dn_type").ToString() '*dn_type*/
                            dirnum_npcode = dr3("DIRNUM_NPCODE").ToString() '/*npcode*/

                            lblSMHata.Text = ""

                        End If

                    Next


                End If



            End If


        End If



        If (chckPrelinked.Checked = False) Then

            If (TB_SM_SERIALNUM.Text <> "") Then
                'Dim dt3 As DataTable = CheckSIM(TB_SM_SERIALNUM.Text.Trim())

                Dim dt3 As DataTable = New DataTable() ' = aktivasyonType()

                If Convert.ToInt32(Session("secim")) = 1 Then
                    dt3 = ccapps.persistent.YenidenAktivasyon.CheckSIM(TB_SM_SERIALNUM.Text.Trim())
                ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                    dt3 = ccapps.persistent.Gpo2Gpo.CheckSIM(TB_SM_SERIALNUM.Text.Trim())
                ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                    dt3 = ccapps.persistent.GPO2Avea.CheckSIM(TB_SM_SERIALNUM.Text.Trim())
                ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                    dt3 = ccapps.persistent.Avea2GPO.CheckSIM(TB_SM_SERIALNUM.Text.Trim())
                ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                    dt3 = ccapps.persistent.CustomerCreate.CheckSIM(TB_SM_SERIALNUM.Text.Trim())
                End If

                If dt3.Rows.Count = 0 Then
                    lblSMHata.Text = "Girmiş olduğunuz ICC-ID deactive durumdadır. Lütfen farklı bir ICC-ID deneyiniz"

                ElseIf dt3.Rows.Count > 0 Then
                    For Each dr3 As DataRow In dt3.Rows
                        If (dr3("sm_status").ToString().Trim() <> "r") Then
                            Dim gen As String = dr3("sm_status").ToString()

                            If dr3("sm_status").ToString() = "d" Then
                                lblSMHata.Text = "Girmiş olduğunuz ICC-ID deactive durumdadır. Lütfen farklı bir ICC-ID deneyiniz"

                            End If

                            If dr3("sm_status").ToString() = "a" Then
                                lblSMHata.Text = "Girmiş olduğunuz ICC-ID zaten kullanılmaktadır. Lütfen farklı bir ICC-ID deneyiniz"

                            End If



                            If dr3("sm_status").ToString() = "r" Then
                                lblSMHata.Text = ""

                            End If


                        End If



                    Next


                End If



            End If


        End If



        TarifeSecim()
        AktivasyonReason()

        'DealerSecim()
        RPServiceStatus()
    End Sub

    Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        ErrorMessage.Text = ""
        Dim confirmValue As String = Request.Form("confirm_value")
        If confirmValue = "Yes" Then
            Try
                Dim sm As String = TB_SM_SERIALNUM.Text.Trim()
                'Dim rpcode As Integer = Convert.ToInt32(DDL_RPCODE.SelectedValue)
                Dim rscode As Integer = Convert.ToInt32(DDL_RS_CODE.SelectedValue)

                Dim rpcode, cntrl As Integer
                If Session("cust_type") = "bireysel" Then
                    cntrl = Convert.ToInt32(Label2.Text)
                    rpcode = cntrl
                Else
                    rpcode = Convert.ToInt32(DDL_RPCODE.SelectedValue)
                End If

                Dim MES As String
                Dim msisdn As String

                If chckPrelinked.Checked = True Then
                    If TB_MSISDN.Text.Length = 10 Then



                        msisdn = "90" + TB_MSISDN.Text.Trim()
                        Dim uluslararasiArama As String = "N"
                        Dim uluslararasiDolasim As String = "N"
                        Dim rehber As String = "N"
                        Dim sc_id As String
                        Dim dealer_custcode As String = TB_NewDealer.Text.Trim()
                        Dim hcode As Integer
                        Dim d_id As Integer
                        Dim d_num As String
                        Dim npcode As Integer
                        Dim d_type As Integer
                        Session("rpcode") = DDL_RPCODE.SelectedItem.ToString()
                        Session("rscode") = DDL_RS_CODE.SelectedItem.ToString()

                        If chck_INTERNATIONAL_CALL.Checked = True Then
                            uluslararasiArama = "Y"
                        End If
                        If chck_INTERNATIONAL_ROAMING.Checked = True Then
                            uluslararasiDolasim = "Y"
                        End If
                        If chck_REHBER.Checked = True Then
                            rehber = "Y"
                        End If


                        ' Dim dt3 As DataTable = GetMsisdn(TB_SM_SERIALNUM.Text.Trim())

                        Dim dt3 As DataTable = New DataTable() ' = aktivasyonType()

                        If Convert.ToInt32(Session("secim")) = 1 Then
                            dt3 = ccapps.persistent.YenidenAktivasyon.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
                        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                            dt3 = ccapps.persistent.Gpo2Gpo.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
                        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                            dt3 = ccapps.persistent.GPO2Avea.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
                        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                            dt3 = ccapps.persistent.Avea2GPO.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
                        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                            dt3 = ccapps.persistent.CustomerCreate.GetMsisdn(TB_SM_SERIALNUM.Text.Trim())
                        End If

                        If dt3.Rows.Count > 0 Then
                            For Each dr3 As DataRow In dt3.Rows
                                smc_id = dr3("SMC_ID").ToString().Trim() '/*smc_id*/
                                sm_id = dr3("SM_ID").ToString().Trim()
                                hlcode = dr3("hlcode").ToString().Trim()
                                dn_id = dr3("DN_ID").ToString().Trim()  '/*dn_id*/
                                dn_num = dr3("dn_num").ToString().Trim() '/*dirnum*/
                                dn_type = dr3("dn_type").ToString().Trim() '*dn_type*/
                                dirnum_npcode = dr3("DIRNUM_NPCODE").ToString().Trim() '/*npcode*/
                            Next
                        End If

                        Session("sim") = TB_SM_SERIALNUM.Text.Trim()
                        Session("msisdn") = dn_num

                        Dim SM_ID2 As Integer = Convert.ToInt32(sm_id)
                        Dim DN_ID2 As Integer = Convert.ToInt32(dn_id)

                        'Dim res As DataTable = CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, MES)


                        Dim res As DataTable = New DataTable() ' = aktivasyonType()

                        If Convert.ToInt32(Session("secim")) = 1 Then
                            res = ccapps.persistent.YenidenAktivasyon.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                            res = ccapps.persistent.Gpo2Gpo.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                            res = ccapps.persistent.GPO2Avea.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                            res = ccapps.persistent.Avea2GPO.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                            res = ccapps.persistent.CustomerCreate.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                        End If

                        TB_MSISDN.Text = msisdn
                        If res.Rows.Count > 0 Then
                            For Each dr2 As DataRow In res.Rows
                                If dr2("co_id").ToString() <> -1 Then
                                    Session("co_id") = dr2("co_id").ToString().Trim()
                                    Session("customer_id") = pin_customer_id
                                    Session("dealer_custcode") = dealer_custcode
                                    Response.Redirect("MusteriGecisSummary.aspx", False)
                                    ErrorMessage.Text = ""
                                Else
                                    ErrorMessage.Text = "Contract Create işlemi gerçekleştirilememiştir.Lütfen girmiş olduğunuz değerleri gözden geçiriniz"
                                End If
                            Next
                        Else
                            ErrorMessage.Text = "Contract Create işlemi gerçekleştirilememiştir."
                        End If
                    Else
                        ErrorMessage.Text = "MSISDN Hatalı Yada Eksik Bilgi İçeriyor."
                    End If
                End If  'chckPrelinked.Checked = True 

                If chckPrelinked.Checked = False Then
                    If TB_MSISDN.Text.Length = 10 Then



                        msisdn = "90" + TB_MSISDN.Text.Trim()
                        Dim uluslararasiArama As String = "N"
                        Dim uluslararasiDolasim As String = "N"
                        Dim rehber As String = "N"
                        Dim sc_id As String
                        Dim dealer_custcode As String = TB_NewDealer.Text.Trim()
                        Dim hcode As Integer
                        Dim d_id As Integer
                        Dim d_num As String
                        Dim npcode As Integer
                        Dim d_type As Integer
                        Session("rpcode") = DDL_RPCODE.SelectedItem.ToString()
                        Session("rscode") = DDL_RS_CODE.SelectedItem.ToString()

                        If chck_INTERNATIONAL_CALL.Checked = True Then
                            uluslararasiArama = "Y"
                        End If
                        If chck_INTERNATIONAL_ROAMING.Checked = True Then
                            uluslararasiDolasim = "Y"
                        End If
                        If chck_REHBER.Checked = True Then
                            rehber = "Y"
                        End If

                        Dim sm_status As String
                        'Dim dt3 As DataTable = GetSIMInfo(TB_SM_SERIALNUM.Text.Trim())


                        Dim dt3 As DataTable = New DataTable() ' = aktivasyonType()

                        If Convert.ToInt32(Session("secim")) = 1 Then
                            dt3 = ccapps.persistent.YenidenAktivasyon.GetSIMInfo(TB_SM_SERIALNUM.Text.Trim())
                        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                            dt3 = ccapps.persistent.Gpo2Gpo.GetSIMInfo(TB_SM_SERIALNUM.Text.Trim())
                        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                            dt3 = ccapps.persistent.GPO2Avea.GetSIMInfo(TB_SM_SERIALNUM.Text.Trim())
                        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                            dt3 = ccapps.persistent.Avea2GPO.GetSIMInfo(TB_SM_SERIALNUM.Text.Trim())
                        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                            dt3 = ccapps.persistent.CustomerCreate.GetSIMInfo(TB_SM_SERIALNUM.Text.Trim())
                        End If

                        If dt3.Rows.Count > 0 Then
                            For Each dr3 As DataRow In dt3.Rows
                                smc_id = dr3("SMC_ID").ToString().Trim() '/*smc_id*/
                                sm_id = dr3("SM_ID").ToString().Trim()
                                sm_status = dr3("SM_STATUS").ToString().Trim()
                            Next
                        End If

                        If sm_status = "a" Then
                            ErrorMessage.Text = "Girmiş olduğunuz SIM kart aktif durumdadır. Lütfen tekrar deneyiniz."
                        ElseIf sm_status = "d" Then
                            ErrorMessage.Text = "Girmiş olduğunuz SIM kart deaktif durumdadır. Lütfen tekrar deneyiniz."
                        End If

                        If sm_status = "r" Then

                            Dim dn_status As String
                            ' Dim dt As DataTable = GetMsisdnInfo(msisdn)

                            Dim dt As DataTable = New DataTable() ' = aktivasyonType()

                            If Convert.ToInt32(Session("secim")) = 1 Then
                                dt = ccapps.persistent.YenidenAktivasyon.GetMsisdnInfo(msisdn)
                            ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                                dt = ccapps.persistent.Gpo2Gpo.GetMsisdnInfo(msisdn)
                            ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                                dt = ccapps.persistent.GPO2Avea.GetMsisdnInfo(msisdn)
                            ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                                dt = ccapps.persistent.Avea2GPO.GetMsisdnInfo(msisdn)
                            ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                                dt = ccapps.persistent.CustomerCreate.GetMsisdnInfo(msisdn)
                            End If

                            dn_id = dt.Rows(0)("DN_ID")
                            dn_status = dt.Rows(0)("DN_STATUS")
                            'Label5.Text = dn_status

                            If dn_status = "n" Then
                                ErrorMessage.Text = "Girmis oldugunuz MSISDN sistemde mevcut degildir. Lutfen tekrar deneyiniz"
                            ElseIf dn_status = "p" Then
                                ErrorMessage.Text = "Girmis oldugunuz MSISDN Prelinked olarak sistemde mevcuttur. Lutfen tekrar deneyiniz"
                            Else
                                If dn_status = "a" Then
                                    ErrorMessage.Text = "Girmiş olduğunuz MSISDN aktif durumdadır. Lütfen tekrar deneyiniz"
                                ElseIf dn_status = "d" Then
                                    ErrorMessage.Text = "Girmiş olduğunuz MSISDN deaktif durumdadır. Lütfen tekrar deneyiniz"
                                End If

                                If dn_status = "r" Then
                                    Session("sim") = TB_SM_SERIALNUM.Text.Trim()
                                    Session("msisdn") = msisdn

                                    Dim SM_ID2 As Integer = Convert.ToInt32(sm_id)
                                    Dim DN_ID2 As Integer = Convert.ToInt32(dn_id)

                                    'Dim res As DataTable = CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, MES)

                                    Dim res As DataTable = New DataTable() ' = aktivasyonType()

                                    If Convert.ToInt32(Session("secim")) = 1 Then
                                        res = ccapps.persistent.YenidenAktivasyon.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                                    ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                                        res = ccapps.persistent.Gpo2Gpo.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                                    ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                                        res = ccapps.persistent.GPO2Avea.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                                    ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                                        res = ccapps.persistent.Avea2GPO.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                                    ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                                        res = ccapps.persistent.CustomerCreate.CreateContract(pin_customer_id, rpcode, rscode, SM_ID2, DN_ID2, rehber, uluslararasiArama, uluslararasiDolasim, dealer_custcode, Session("user"), MES)
                                    End If


                                    'Label5.Text = "basaşarılı"
                                    If res.Rows.Count > 0 Then
                                        For Each dr2 As DataRow In res.Rows
                                            If dr2("co_id").ToString() <> -1 Then
                                                Session("co_id") = dr2("co_id").ToString().Trim()
                                                Session("customer_id") = pin_customer_id
                                                Session("dealer_custcode") = dealer_custcode
                                                Response.Redirect("MusteriGecisSummary.aspx", False)
                                                ErrorMessage.Text = ""
                                            Else
                                                ErrorMessage.Text = "Contract Create işlemi gerçekleştirilememiştir.Lütfen girmiş olduğunuz değerleri gözden geçiriniz"
                                            End If
                                        Next
                                    Else
                                        ErrorMessage.Text = "Contract Create işlemi gerçekleştirilememiştir."
                                    End If
                                End If 'dn_status=r 
                            End If

                        End If 'Sm-status=r
                    Else
                        ErrorMessage.Text = "MSISDN Hatalı Yada Eksik Bilgi İçeriyor."
                    End If

                End If

            Catch ex As Exception
                ErrorMessage.Text = ex.Message


                'Session("message") = ex.Message
                'Response.Clear()
                'Response.Status = "302 Object Moved"
                'Response.RedirectLocation = "CX_Exception.aspx"
                'Response.End()




            End Try
        End If


    End Sub



    Protected Sub DDL_RPCODE_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDL_RPCODE.SelectedIndexChanged
        RPServiceStatus()
    End Sub

    Private Sub RPServiceStatus(ByVal customer_id As Integer)
        'Dim dtRpcode As DataTable = GetRPCodeInfo(customer_id) '25.02.2013
        Dim dtRpcode As DataTable = New DataTable() ' = aktivasyonType()

        If Convert.ToInt32(Session("secim")) = 1 Then
            dtRpcode = ccapps.persistent.YenidenAktivasyon.GetRPCodeInfo(customer_id)
        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
            dtRpcode = ccapps.persistent.Gpo2Gpo.GetRPCodeInfo(customer_id)
        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
            dtRpcode = ccapps.persistent.GPO2Avea.GetRPCodeInfo(customer_id)
        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
            dtRpcode = ccapps.persistent.Avea2GPO.GetRPCodeInfo(customer_id)
        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
            dtRpcode = ccapps.persistent.CustomerCreate.GetRPCodeInfo(customer_id)
        End If


        Dim rpcode As Integer = Convert.ToInt32(dtRpcode.Rows(0)("tmcode").ToString()) '25.02.2013



        'Dim dt2 As DataTable = GetRPServiceStatus(rpcode)

        Dim dt2 As DataTable = New DataTable() ' = aktivasyonType()

        If Convert.ToInt32(Session("secim")) = 1 Then
            dt2 = ccapps.persistent.YenidenAktivasyon.GetRPServiceStatus(rpcode)
        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
            dt2 = ccapps.persistent.Gpo2Gpo.GetRPServiceStatus(rpcode)
        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
            dt2 = ccapps.persistent.GPO2Avea.GetRPServiceStatus(rpcode)
        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
            dt2 = ccapps.persistent.Avea2GPO.GetRPServiceStatus(rpcode)
        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
            dt2 = ccapps.persistent.CustomerCreate.GetRPServiceStatus(rpcode)
        End If
        Dim flag1 As Integer = 0
        Dim flag2 As Integer = 0
        If dt2.Rows.Count > 0 Then
            For Each dr2 As DataRow In dt2.Rows
                If dr2("sncode").ToString() = "40" Then

                    chck_INTERNATIONAL_CALL.Enabled = True
                    flag1 = 1
                Else
                    If flag1 <> 1 Then
                        chck_INTERNATIONAL_CALL.Enabled = False
                        'chck_INTERNATIONAL_CALL.Checked = False
                    End If
                End If

                If dr2("sncode").ToString() = "37" Then

                    chck_INTERNATIONAL_ROAMING.Enabled = True
                    flag2 = 1
                Else
                    If flag2 <> 1 Then
                        chck_INTERNATIONAL_ROAMING.Enabled = False
                        'chck_INTERNATIONAL_ROAMING.Checked = False
                    End If


                End If

            Next
        Else
            chck_INTERNATIONAL_CALL.Enabled = False
            chck_INTERNATIONAL_ROAMING.Enabled = False
        End If
    End Sub

    Private Sub RPServiceStatus()
        'Dim dt2 As DataTable = GetRPServiceStatus(DDL_RPCODE.SelectedValue)

        Dim dt2 As DataTable = New DataTable() ' = aktivasyonType()

        If Convert.ToInt32(Session("secim")) = 1 Then
            dt2 = ccapps.persistent.YenidenAktivasyon.GetRPServiceStatus(DDL_RPCODE.SelectedValue)
        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
            dt2 = ccapps.persistent.Gpo2Gpo.GetRPServiceStatus(DDL_RPCODE.SelectedValue)
        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
            dt2 = ccapps.persistent.GPO2Avea.GetRPServiceStatus(DDL_RPCODE.SelectedValue)
        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
            dt2 = ccapps.persistent.Avea2GPO.GetRPServiceStatus(DDL_RPCODE.SelectedValue)
        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
            dt2 = ccapps.persistent.CustomerCreate.GetRPServiceStatus(DDL_RPCODE.SelectedValue)
        End If
        Dim flag1 As Integer = 0
        Dim flag2 As Integer = 0

        If dt2.Rows.Count > 0 Then
            For Each dr2 As DataRow In dt2.Rows
                If dr2("sncode").ToString() = "40" Then

                    chck_INTERNATIONAL_CALL.Enabled = True
                    flag1 = 1
                Else
                    If flag1 <> 1 Then
                        chck_INTERNATIONAL_CALL.Enabled = False
                        'chck_INTERNATIONAL_CALL.Checked = False
                    End If
                End If

                If dr2("sncode").ToString() = "37" Then

                    chck_INTERNATIONAL_ROAMING.Enabled = True
                    flag2 = 1
                Else
                    If flag2 <> 1 Then
                        chck_INTERNATIONAL_ROAMING.Enabled = False
                        'chck_INTERNATIONAL_ROAMING.Checked = False
                    End If


                End If

            Next
        Else
            chck_INTERNATIONAL_CALL.Enabled = False
            chck_INTERNATIONAL_ROAMING.Enabled = False
        End If
    End Sub

    Private Sub RPServiceStatusBireysel(ByVal rpcode As Integer)
        'Dim dt2 As DataTable = GetRPServiceStatus(rpcode)

        Dim dt2 As DataTable = New DataTable() ' = aktivasyonType()
        Dim flag1 As Integer = 0
        Dim flag2 As Integer = 0
        If Convert.ToInt32(Session("secim")) = 1 Then
            dt2 = ccapps.persistent.YenidenAktivasyon.GetRPServiceStatus(rpcode)
        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
            dt2 = ccapps.persistent.Gpo2Gpo.GetRPServiceStatus(rpcode)
        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
            dt2 = ccapps.persistent.GPO2Avea.GetRPServiceStatus(rpcode)
        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
            dt2 = ccapps.persistent.Avea2GPO.GetRPServiceStatus(rpcode)
        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
            dt2 = ccapps.persistent.CustomerCreate.GetRPServiceStatus(rpcode)
        End If


        If dt2.Rows.Count > 0 Then
            For Each dr2 As DataRow In dt2.Rows
                If dr2("sncode").ToString() = "40" Then

                    chck_INTERNATIONAL_CALL.Enabled = True
                    flag1 = 1
                Else
                    If flag1 <> 1 Then
                        chck_INTERNATIONAL_CALL.Enabled = False
                        'chck_INTERNATIONAL_CALL.Checked = False
                    End If
                End If

                If dr2("sncode").ToString() = "37" Then

                    chck_INTERNATIONAL_ROAMING.Enabled = True
                    flag2 = 1
                Else
                    If flag2 <> 1 Then
                        chck_INTERNATIONAL_ROAMING.Enabled = False
                        ' chck_INTERNATIONAL_ROAMING.Checked = False
                    End If


                End If

            Next
        Else
            chck_INTERNATIONAL_CALL.Enabled = False
            chck_INTERNATIONAL_ROAMING.Enabled = False
        End If
    End Sub

    Protected Sub chckPrelinked_CheckedChanged(sender As Object, e As EventArgs) Handles chckPrelinked.CheckedChanged
        If (chckPrelinked.Checked = True) Then
            If (TB_SM_SERIALNUM.Text <> "") Then
                'Dim dt3 As DataTable = GetMsisdn(TB_SM_SERIALNUM.Text)

                Dim dt3 As DataTable = New DataTable() ' = aktivasyonType()

                If Convert.ToInt32(Session("secim")) = 1 Then
                    dt3 = ccapps.persistent.YenidenAktivasyon.GetMsisdn(TB_SM_SERIALNUM.Text)
                ElseIf Convert.ToInt32(Session("secim")) = 2 Then
                    dt3 = ccapps.persistent.Gpo2Gpo.GetMsisdn(TB_SM_SERIALNUM.Text)
                ElseIf Convert.ToInt32(Session("secim")) = 3 Then
                    dt3 = ccapps.persistent.GPO2Avea.GetMsisdn(TB_SM_SERIALNUM.Text)
                ElseIf Convert.ToInt32(Session("secim")) = 4 Then
                    dt3 = ccapps.persistent.Avea2GPO.GetMsisdn(TB_SM_SERIALNUM.Text)
                ElseIf Convert.ToInt32(Session("secim")) = 5 Then
                    dt3 = ccapps.persistent.CustomerCreate.GetMsisdn(TB_SM_SERIALNUM.Text)
                End If

                If dt3.Rows.Count > 0 Then
                    For Each dr3 As DataRow In dt3.Rows

                        TB_MSISDN.Text = dr3("dn_num").ToString()

                        smc_id = dr3("SMC_ID").ToString() '/*smc_id*/
                        sm_id = dr3("SM_ID").ToString()
                        hlcode = dr3("hlcode").ToString()
                        dn_id = dr3("DN_ID").ToString()   '/*dn_id*/
                        dn_num = dr3("dn_num").ToString() '/*dirnum*/
                        dn_type = dr3("dn_type").ToString() '*dn_type*/
                        dirnum_npcode = dr3("DIRNUM_NPCODE").ToString() '/*npcode*/



                    Next


                End If



            End If
            TarifeSecim()
            AktivasyonReason()

            ' DealerSecim()

        End If



        If (chckPrelinked.Checked = True) Then
            TB_MSISDN.Text = ""
            RPServiceStatus()
        End If
    End Sub

    Protected Sub TB_NewDealer_TextChanged(sender As Object, e As EventArgs) Handles TB_NewDealer.TextChanged
        Dim dt As DataTable = New DataTable() ' DealerControl(TB_NewDealer.Text)
        If Convert.ToInt32(Session("secim")) = 1 Then
            dt = ccapps.persistent.YenidenAktivasyon.DealerControl(TB_NewDealer.Text)
        ElseIf Convert.ToInt32(Session("secim")) = 2 Then
            dt = ccapps.persistent.Gpo2Gpo.DealerControl(TB_NewDealer.Text)
        ElseIf Convert.ToInt32(Session("secim")) = 3 Then
            dt = ccapps.persistent.GPO2Avea.DealerControl(TB_NewDealer.Text)
        ElseIf Convert.ToInt32(Session("secim")) = 4 Then
            dt = ccapps.persistent.Avea2GPO.DealerControl(TB_NewDealer.Text)
        ElseIf Convert.ToInt32(Session("secim")) = 5 Then
            dt = ccapps.persistent.CustomerCreate.DealerControl(TB_NewDealer.Text)
        End If
        'Label5.Text += dt.Rows(0)(0).ToString() 
        If dt.Rows.Count > 0 Then
            If Convert.ToInt32(dt.Rows(0)(0).ToString()) = 0 Then
                Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('Hatalı Dealer.');</script>")
                TB_NewDealer.Text = ""
            End If
        Else
            Me.Page.RegisterStartupScript("javascript", "<script language=""javascript"">alert('Hatalı Dealer.');</script>")
            TB_NewDealer.Text = ""
        End If
    End Sub
End Class


 